package com.coffeeloversupportlibrary.coffeelover.domain.article.cotegory;
import com.coffeeloversupportlibrary.coffeelover.callback.ModelCallBack;
import com.coffeeloversupportlibrary.coffeelover.domain.article.entity.Article;
import com.coffeeloversupportlibrary.core.base.BaseViewModel;
import com.coffeeloversupportlibrary.core.base.livadata.SingleLiveEvent;
import com.coffeeloversupportlibrary.core.data.DataRepository;

import java.util.List;

/**
 * @author puyv
 * @createTime 2021/11/22 15:17
 * @projectName CoffeeLoverSupportLibrary
 * @className CategoryViewModel.java
 * @description TODO   ViewModel 层准备数据   两种请求类型   1.初始化定量请求数据（type number）  2.加载更多数据
 *
 */
public class CategoryViewModel extends BaseViewModel<CategoryModel> {



    private SingleLiveEvent<List<Article>> categoryOne=new SingleLiveEvent<>();
    private SingleLiveEvent<List<Article>> categoryTwo=new SingleLiveEvent<>();
    private SingleLiveEvent<List<Article>> categoryThree=new SingleLiveEvent<>();
    private SingleLiveEvent<List<Article>> categoryFour=new SingleLiveEvent<>();
    private SingleLiveEvent<List<Article>> categoryFive=new SingleLiveEvent<>();


    public SingleLiveEvent<List<Article>> getCategoryOne() {
        return categoryOne;
    }

    public SingleLiveEvent<List<Article>> getCategoryTwo() {
        return categoryTwo;
    }

    public SingleLiveEvent<List<Article>> getCategoryThree() {
        return categoryThree;
    }

    public SingleLiveEvent<List<Article>> getCategoryFour() {
        return categoryFour;
    }

    public SingleLiveEvent<List<Article>> getCategoryFive() {
        return categoryFive;
    }


    public void initCategoryArticle(int articleType){
        mModel.getArticlesByType(new ModelCallBack<List<Article>, String>() {
            @Override
            public void onSuccess(List<Article> articles) {
                if(null!=articles){
                    init(articleType,articles);
                }
            }

            @Override
            public void Failure(String s) {

            }
        }, articleType);

    }

    // TODO: 2021/11/22 暂不处理加载更多功能
    public void loadMoreArticle(int articleType){

    }
    @Override
    protected void setModel() {
        // TODO: 2021/11/23     为什么model ==null   hehe
//        new CategoryModel(DataRepository.getInstance());
        mModel=new CategoryModel(DataRepository.getInstance());
    }

    private void init(int articleType,List<Article> lists){
        switch (articleType){
            case 1:categoryOne.setValue(lists);
                break;
            case 2:categoryTwo.setValue(lists);
                break;
            case 3:categoryThree.setValue(lists);
                break;
            case 4:categoryFour.setValue(lists);
                break;
            case 5:categoryFive.setValue(lists);
                break;
        }
    }



}
